package Eyjafjalla.power;

import Eyjafjalla.patch.CloudPatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.megacrit.cardcrawl.actions.common.ReducePowerAction;
import com.megacrit.cardcrawl.actions.common.RemoveSpecificPowerAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.helpers.ImageMaster;
import com.megacrit.cardcrawl.localization.PowerStrings;

public class RedCloudPower extends AbstractEyjafjallaPower {
    public static final String POWER_ID = "eyjafjalla:RedCloudPower";
    private static final PowerStrings powerStrings;

    public RedCloudPower(AbstractCreature owner, int amount){
        this.name = powerStrings.NAME;
        this.ID = POWER_ID;
        this.owner = owner;
        this.isPlayer = this.owner.isPlayer;
        this.amount = amount;
        this.updateDescription();
        String path128 = "EyjafjallaResources/img/power/RedCloudPower_84.png";
        String path48 = "EyjafjallaResources/img/power/RedCloudPower_32.png";
        this.region128 = new TextureAtlas.AtlasRegion(ImageMaster.loadImage(path128),0,0,84,84);
        this.region48 = new TextureAtlas.AtlasRegion(ImageMaster.loadImage(path48),0,0,32,32);
        this.type = PowerType.DEBUFF;
    }

    boolean isPlayer;
    boolean toRemove = false;

    public float atDamageReceive(float damage, DamageInfo.DamageType type) {
        if (type == DamageInfo.DamageType.NORMAL&&this.amount>0) {
            float bl = 1+ ((float) this.amount) * 0.5F;
            return damage*bl;
        } else {
            return damage;
        }
    }

    @Override
    public int onAttacked(DamageInfo info, int damageAmount) {
        if(info.type== DamageInfo.DamageType.NORMAL){
            if(!isPlayer)
                addToBot(new RemoveSpecificPowerAction(this.owner,this.owner,this));
            else {
                this.toRemove = true;
            }
        }
        return super.onAttacked(info, damageAmount);
    }

    @Override
    public void atEndOfRound() {
        if(isPlayer&&toRemove){
            addToBot(new RemoveSpecificPowerAction(this.owner,this.owner,this));
        }
    }

    @Override
    public void updateDescription() {
        int bl = 50*this.amount;
        this.description = powerStrings.DESCRIPTIONS[0] + bl + (isPlayer?powerStrings.DESCRIPTIONS[2]:powerStrings.DESCRIPTIONS[1]);
    }

    static {
        powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
    }
}

